<?php

/* -----------------------------------------------------------------
 * 	$Id: blog_start.php 1315 2014-12-15 15:19:11Z akausch $
 * 	Copyright (c) 2011-2021 commerce:SEO by Webdesign Erfurt
 * Copyright by H&S eCom 
 * @author little Pit(S.B.)
 * 	http://www.commerce-seo.de : www.indiv-style.de
 * ------------------------------------------------------------------
 * 	based on:
 * 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
 * 	(c) 2002-2003 osCommerce - www.oscommerce.com
 * 	(c) 2003     nextcommerce - www.nextcommerce.org
 * 	(c) 2005     xt:Commerce - www.xt-commerce.com
 * 	Released under the GNU General Public License
 * --------------------------------------------------------------- */

defined("_VALID_XTC") or die("Direct access to this location isn't allowed.");
if (!column_exists (TABLE_BLOG_START,'slider_set')) {
	xtc_db_query("ALTER TABLE " . TABLE_BLOG_START . " ADD COLUMN slider_set int(11) NOT NULL DEFAULT '0';");
}
$module_smarty = new Smarty;
$module_smarty->assign('txt', $coo_text_mgr->v_section_content_array['blog']);
$module_smarty->assign('FORM', xtc_draw_form('blogstart', FILENAME_BLOG, 'action=save_start', 'post', 'enctype="multipart/form-data"'));

if ($_GET['action'] == 'startsite') {
    $module_smarty->assign('HIDDEN', xtc_draw_hidden_field('action', 'update') . xtc_draw_hidden_field('id', '1'));
}
$languages = xtc_get_languages();
for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
    $items = xtc_db_fetch_array(xtc_db_query("SELECT *
									FROM " . TABLE_BLOG_START . "
									WHERE language_id = '" . (int) $languages[$i]['id'] . "'
									AND id = '1' ")
    );

	$slider_set_sql = xtc_db_query("SELECT slider_id AS id, slider_title AS text FROM cseo_slider_gallery where language_id = '" . (int) $languages[$i]['id'] . "' GROUP BY slider_title");
	$slider_set_array = array(array('id' => 0, 'text' => TEXT_SELECT));
	while ($slider_set = xtc_db_fetch_array($slider_set_sql)) {
		 $slider_set_array[] = array('id' => $slider_set['id'], 'text' => $slider_set['text']);
	}
	if (USE_WYSIWYG == 'true') {
		if (file_exists('includes/ckfinder/ckfinder.js')) {
			$field_sdesc_wy = "<script src=\"includes/ckfinder/ckfinder.js\"></script>
								<script>
									var newCKEdit = CKEDITOR.replace('description_" . $languages[$i]['id'] . "');
									CKFinder.setupCKEditor(newCKEdit, 'includes/ckfinder/');
								</script>
								";
		} else {
			$field_sdesc_wy = "<script>
				CKEDITOR.replace('description_" . $languages[$i]['id'] . "', {
					toolbar: \"ImageMapper\",
					language: \"" . $_SESSION['language_code'] . "\",
					baseHref: \"" . (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG . "\",
					filebrowserBrowseUrl: \"includes/ckeditor/filemanager/index.html\"
				});
			</script>
			";
		}
	}

    $startedit[$i] = array(
        'langid' => $languages[$i]['id'],
        'langname' => $languages[$i]['name'],
        'langstatus' => $languages[$i]['status'],
        'field_slider' => xtc_draw_pull_down_menu('slider_set[' . $languages[$i]['id'] . ']', $slider_set_array, $items['slider_set'], 'class="btn btn-default"'),
        'lang_images' => xtc_image(DIR_WS_LANGUAGES . $languages[$i]['directory'] . '/' . $languages[$i]['image'], $languages[$i]['name']),
        'field_mtitle' => xtc_draw_input_field('meta_title_' . $languages[$i]['id'], $items['meta_title'], ''),
        'field_mdesc' => xtc_draw_input_field('meta_description_' . $languages[$i]['id'], $items['meta_description'], ''),
        'field_mkeys' => xtc_draw_input_field('meta_keywords_' . $languages[$i]['id'], $items['meta_keywords'], ''),
        'field_ldesc' => xtc_draw_textarea_field('description_' . $languages[$i]['id'], '', '100', '50', $items['description'], ''),
        'field_sdesc_wy' => $field_sdesc_wy
    );
}

$myimages = xtc_get_blogstart_mo_images();
for ($i = 0; $i < PICSTART; $i++) {
    $Bildnummer = TEXT_PRODUCTS_IMAGE . ' ' . ($i + 1);
    $bildda = $myimages[$i];
    $Bild = xtc_image(DIR_WS_CATALOG_IMAGES . 'blog_image/thumbnail_images/' . $myimages[$i]['image'], 'is_images_' . ($i + 1));
    $Bildfeld = xtc_draw_file_field('ism_image_' . ($i + 1)) . '<br />' . $myimages[$i]['image'] . xtc_draw_hidden_field('ismv_image_' . ($i + 1), $myimages[$i]['image']);
    $Bildfeld2 = xtc_draw_selection_field('imageremove[]', 'checkbox', $myimages[$i]['image']) . ' ' . TEXT_DELETE;
    $Bildfeld3 = xtc_draw_file_field('ism_image_' . ($i + 1)) . xtc_draw_hidden_field('ismv_image_' . ($i + 1), $myimages[$i]['image']);

    $bilder[$i] = array(
        'bildfeld0' => $bildda,
        'bildfeld1' => $Bildnummer,
        'bildfeld2' => $Bild,
        'bildfeld3' => $Bildfeld,
        'bildfeld4' => $Bildfeld2,
        'bildfeld5' => $Bildfeld3
    );
}

$group_ids = '';
$customers_statuses_array = xtc_get_customers_statuses();
if (strstr($group_ids, 'c_all_group')) {
    $group_ids = 'c_all_group,';
    foreach ($customers_statuses_array AS $t_gm_key => $t_gm_value) {
        $group_ids .='c_' . $t_gm_value['id'] . '_group,';
    }
}
$mygroup = xtc_db_fetch_array(xtc_db_query("select group_ids FROM " . TABLE_BLOG_START . " WHERE id = 1 AND language_id = '" . $_SESSION['languages_id'] . "' "));
if (GROUP_CHECK == 'true') {
    $customers_statuses_array = xtc_get_customers_statuses();
    $customers_statuses_array = array_merge(array(array('id' => 'all', 'text' => TXT_ALL)), $customers_statuses_array);
    for ($i = 0; $i < count($customers_statuses_array); $i++) {
        if (strstr($mygroup['group_ids'], 'c_' . $customers_statuses_array[$i]['id'] . '_group')) {
            $checked = 'checked ';
        } else {
            $checked = '';
        }
        $kundengruppe = '<input type="checkbox" name="groups[]" value="' . $customers_statuses_array[$i]['id'] . '"' . $checked . '> ' . $customers_statuses_array[$i]['text'] . '<br />';
        $kundengr[$i] = array(
            'KGRUPPE' => $kundengruppe
        );
    }
    $module_smarty->assign('KGRUPPE', ENTRY_CUSTOMERS_STATUS);
}
$module_smarty->assign('BILDER', $bilder);
$module_smarty->assign('GRUPPE', $kundengr);
$module_smarty->assign('START_EDIT', $startedit);
$module_smarty->assign('FORM_END', '</form>');
$module_smarty->assign('language', $_SESSION['language']);
$module_smarty->caching = false;
$module_smarty->template_dir = DIR_FS_CATALOG . 'admin/templates/';
$module_smarty->compile_dir = DIR_FS_CATALOG . 'admin/templates_c';
$ssmodule = $module_smarty->fetch(CURRENT_ADMIN_TEMPLATE . '/blog_start.html');
$smarty->assign('MODULE_blog_start', $ssmodule);
